APS 2025 Example Model

Of course, in reality, creating a stock-and-flow model isn’t a one-shot process. The variables, connections, and equations will have to be experimented with and tweaked to accurately represent the system’s behavior. Let’s explore how to iteratively build stock-and-flow models by creating a simplified model of burnout, inspired by classic system dynamics models.

Let’s say Maya has just switched from a part-time to a full-time job, and she wants to impress her supervisor. She is working hard and putting in extra hours. However, the more she works, the more projects, meetings, and emails pile on - work breeds work. This comes at the cost of her sleep, which she can only sustain for a limited time. Maya ends up working far beyond her capacity, to the point where she is unable to work at all.

sfm = xmile()
summary(sfm)
## Your model contains:
## * 0 Stocks
## * 0 Flows
## * 0 Constants
## * 0 Auxiliaries
## * 0 Graphical Functions
## * 0 Custom model units
## * 0 Macros
## 
## The model will be simulated from 0.0 to 100.0 s (dt = 0.01) with solver euler in Julia.
sfm = sfm %>% 
  build("workload", "stock", eqn = 4, units = "hours/day") 

sim = simulate(sfm)
plot(sim)
sfm = sfm %>% header(name = "Maya's Burnout") %>%
  sim_specs(stop = 12, time_units = "month") 

sim = simulate(sfm)
plot(sim)
sfm = sfm %>% 
  build("new_tasks", "flow", eqn = "workload * work_growth",
        to = "workload", units="hours/day/month") %>%
  build("work_growth", "constant", eqn = 1.5, units = "1/month")

sim = simulate(sfm)
plot(sim)
sfm = sfm %>%
  build("sleep", "stock", eqn = "necessary_sleep", units = "hours/day") %>%
  build("necessary_sleep", "constant", eqn = 8, units = "hours/day") %>%
  build("worry_about_work", "flow", 
        eqn = "workload * worry_factor", from = "sleep", units = "hours/day/month") %>%
  build("worry_factor", "constant", eqn = .1, units = "1/month") 

sim = simulate(sfm)
plot(sim)
sfm = sfm %>%
  build("need_for_rest",  "flow",
        eqn = "workload * necessary_sleep / sleep / u('1month')",
        from = "workload",
        units = "hours/day/month")  

sim = simulate(sfm)
plot(sim)

Model iteration

sfm = sfm %>% build("workload", eqn = 8)
sfm = sfm %>% build("sleep", change_name = "sleep_hours")
sfm = sfm %>% build("necessary_sleep", change_type = "aux")
sfm = sfm %>% build("workload", erase = TRUE)
sfm = xmile() %>%
  macro("sig", eqn = "function(x, slope = 1, midpoint = .5){
        1 / (1 + exp(-slope*(x-midpoint)))
        }")

Units

regex

custom

sfm = sfm %>%
  model_units("quality", doc = "Quality of life; also known as utility") %>%
  model_units("QALY", eqn = "years*quality", doc = "Quality-adjusted life year")

in equations